/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.fzhucc.modules.sciTechnologyDemand.controller;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.modules.sciTechnologyDemand.domain.SciTechnologyDemandMate;
import com.fzhucc.modules.sciTechnologyDemand.domain.dto.*;
import com.fzhucc.modules.sciTechnologyDemand.service.SciTechnologyDemandMateService;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2023-12-15
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "企业需求匹配劳模工匠记录表管理")
@RequestMapping("/api/sciTechnologyDemandMate")
public class SciTechnologyDemandMateController {

    private final SciTechnologyDemandMateService sciTechnologyDemandMateService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciTechnologyDemandMate:list')")
    public void exportSciTechnologyDemandMate(HttpServletResponse response, SciTechnologyDemandMateQueryCriteria criteria) throws IOException {
        sciTechnologyDemandMateService.download(sciTechnologyDemandMateService.queryAll(criteria), response);
    }

    @GetMapping
    @AnonymousAccess
    @Log("查询企业需求匹配劳模工匠记录表")
    @ApiOperation("查询企业需求匹配劳模工匠记录表")
    //@PreAuthorize("@el.check('sciTechnologyDemandMate:list')")
    public ResponseEntity<Object> querySciTechnologyDemandMate(SciTechnologyDemandMateQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(sciTechnologyDemandMateService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    @GetMapping(value = "/getAllMateSciPersonnelInfo")
    @Log("查询可分配的所有劳模工匠")
    @ApiOperation("查询可分配的所有劳模工匠")
    public ResponseEntity<Object> getAllMateSciPersonnelInfo(@RequestParam String name) {
        return new ResponseEntity<>(sciTechnologyDemandMateService.getAllMateSciPersonnelInfo(name), HttpStatus.OK);
    }

    @PostMapping
    @Log("新增企业需求匹配劳模工匠记录表")
    @ApiOperation("新增企业需求匹配劳模工匠记录表")
    //@PreAuthorize("@el.check('sciTechnologyDemandMate:add')")
    public ResponseEntity<Object> createSciTechnologyDemandMate(@Validated @RequestBody SciTechnologyDemandMate resources) {
        return new ResponseEntity<>(sciTechnologyDemandMateService.create(resources), HttpStatus.CREATED);
    }

    /*@PostMapping(value = "/select/h5")
    @Log("h5选中匹配到的劳模")
    @ApiOperation("h5选中匹配到的劳模")
    public ResponseEntity<Object> selecth5(@Validated @RequestBody ListSelectModelDto resources) {
        sciTechnologyDemandMateService.selecth5(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PostMapping(value = "/cancelSelect/h5")
    @Log("h5取消选中匹配到的劳模")
    @ApiOperation("h5取消选中匹配到的劳模")
    public ResponseEntity<Object> cancelSelecth5(@Validated @RequestBody ListSelectModelDto resources) {
        sciTechnologyDemandMateService.cancelSelecth5(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }*/


    @PostMapping(value = "/select")
    @Log("选中匹配到的劳模")
    @ApiOperation("选中匹配到的劳模")
    public ResponseEntity<Object> select(@Validated @RequestBody ListSelectModelDto2 resources) {
        sciTechnologyDemandMateService.select(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PostMapping(value = "/cancelSelect")
    @Log("取消选中匹配到的劳模")
    @ApiOperation("取消选中匹配到的劳模")
    public ResponseEntity<Object> cancelSelect(@Validated @RequestBody ListSelectModelDto2 resources) {
        sciTechnologyDemandMateService.cancelSelect(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @GetMapping(value = "/mate")
    @Log("匹配")
    @ApiOperation("匹配")
    //@PreAuthorize("@el.check('sciTechnologyDemandMate:add')")
    public ResponseEntity<Object> mate(SciTechnologyDemandMateQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity<>(sciTechnologyDemandMateService.mateWithMateSort(criteria, pageable), HttpStatus.CREATED);
    }

    @DeleteMapping
    @Log("删除企业需求匹配劳模工匠记录表")
    @ApiOperation("删除企业需求匹配劳模工匠记录表")
    //@PreAuthorize("@el.check('sciTechnologyDemandMate:del')")
    public ResponseEntity<Object> deleteSciTechnologyDemandMate(@RequestBody Integer[] ids) {
        sciTechnologyDemandMateService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}